// 用户名
var reg1 = /^[\w]+$/
var user_name = document.querySelector('.user_name')
user_name.addEventListener('blur', () => {
    if (!reg1.test(event.target.value)) {
        event.target.nextElementSibling.style.display = 'block'
    } else {
        event.target.nextElementSibling.style.display = 'none'
    }
})

// 密码
var password = document.querySelector('.password')
var reg2 = /^.{6,}$/
password.addEventListener('blur', () => {
    if (!reg2.test(event.target.value)) {
        event.target.nextElementSibling.style.display = 'block'
    } else {
        event.target.nextElementSibling.style.display = 'none'
    }
})

// 邮箱
var eml = document.querySelector('.eml')
var reg3 = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/
eml.addEventListener('blur', () => {
    if (!reg3.test(event.target.value)) {
        event.target.nextElementSibling.style.display = 'block'
    } else {
        event.target.nextElementSibling.style.display = 'none'
    }
})

// 跳转
function fn() {
    $.ajax({
        type: 'post',
        url: 'http://47.94.4.201/index.php/index/index/register',
        data: {
            name: $('.user_name').val(),
            pwd: $('.password').val(),
            emails: $('.eml').val(),
        },
        dataType: 'json',
        success: (a) => {
            if (a.msg == '添加成功') {
                location.assign('../登录/登录.html')
            } else {
                alert(a.msg)
                location.reload(true)
            }
        },
        error: e => {
            console.log(e);
        }
    })
}
